{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 安装GPU版本的tensorflow\n",
    "\n",
    "## 环境要求\n",
    "\n",
    "根据tensorflow-gpu 2.x的配置要求可知，需要Diver版本至少为418，CUDA版本至少为10.1,CUDNN版本至少为7.6。  \n",
    "\n",
    "![](assets/7.png)  \n",
    "![](assets/8.png)\n",
    "\n",
    "## 检查当前的环境配置\n",
    "\n",
    "```\n",
    "nvidia-smi -l\n",
    "```\n",
    "\n",
    "## 安装\n",
    "\n",
    "```\n",
    "conda install tensorflow-gpu\n",
    "```\n",
    "\n",
    "# 使用GPU\n",
    "\n",
    "如果环境中有GPU，且正确配置，软件也安装正确。不需要改动代码，默认就是在GPU上运行的。\n",
    "\n",
    "# 判断GPU是否可用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "\n",
    "# print(tf.test.is_gpu_available())\n",
    "tf.config.list_physical_devices('GPU')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 临时禁用GPU"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "os.environ[\"CUDA_VISIBLE_DEVICES\"]=\"-1\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
